package com.t.bricks.bussiness.service.tts.impl;

import org.springframework.stereotype.Service;

import com.t.bricks.bussiness.service.tts.TextToSoundService;
import com.t.bricks.model.MsgEmity;
import com.t.bricks.utils.tts.TextToSoundUtil;

@Service
public class TextToSoundServiceImpl implements TextToSoundService {
	
	private TextToSoundUtil textToSoundUtil = null;
	
	/**
	 * textToSoundUtil
	 * @return
	 */
	private TextToSoundUtil getTextToSoundUtil() {
		if (null != textToSoundUtil) {
			return textToSoundUtil;
		}
		
		synchronized(this) {
			if (null != textToSoundUtil) {//再判断一次
				return textToSoundUtil;
			}
			
			textToSoundUtil = new TextToSoundUtil();
		}
		
		return textToSoundUtil;
	}
	
	/**
	 * 把文字内容转换成mp3格式音频
	 * @param text
	 * @return
	 */
	@Override
	public MsgEmity toMp3(String text) {
		MsgEmity me = getTextToSoundUtil().toMp3(text, null, null);
		if (!me.isSuccess()) {
			return me.setData((Integer)me.getData() + 7000);
		}
		
		return me; 
	}
	
	/**
	 * 把文字内容转换成mp3格式音频
	 * @param text
	 * @param tempPath
	 * @param fileName
	 * @return
	 */
	@Override
	public MsgEmity toMp3(String text, String tempPath, String fileName) {
		MsgEmity me = getTextToSoundUtil().toMp3(text, tempPath, fileName);
		if (!me.isSuccess()) {
			return me.setData((Integer)me.getData() + 7000);
		}
		
		return me; 
	}

	/**
	 * 把文字内容转换成PCM格式音频
	 * @param text
	 * @return
	 */
	@Override
	public MsgEmity toPcm(String text) {
		MsgEmity me = getTextToSoundUtil().toPcm(text, null, null);
		if (!me.isSuccess()) {
			return me.setData((Integer)me.getData() + 7000);
		}
		
		return me;
	}

	/**
	 * 把文字内容转换成PCM格式音频
	 * @param text
	 * @param tempPath
	 * @param fileName
	 * @return
	 */
	@Override
	public MsgEmity toPcm(String text, String tempPath, String fileName) {
		MsgEmity me = getTextToSoundUtil().toPcm(text, tempPath, fileName);
		if (!me.isSuccess()) {
			return me.setData((Integer)me.getData() + 7000);
		}
		
		return me;
	}

}
